package com.wlr.study.leetcode;

public class LeetCode202 {
    public boolean isHappy(int n) {
        int slow = n, fast = n;
        do{
            slow = bitSquareSum(slow);
            fast = bitSquareSum(fast);
            fast = bitSquareSum(fast);
        }while(slow != fast);

        return slow == 1;
    }

    public int bitSquareSum(int n){
        int sum = 0;
        while(n>0){
            int bit=n%10;
            sum+=bit*bit;
            n=n/10;
        }
        return sum;
    }

    public static void main(String[] args) {
        LeetCode202 leetCode202 = new LeetCode202();
        System.out.println(leetCode202.isHappy(19));
    }
}
